setClass("HierNonParamClusterAlg",contains="VNonParamClusterAlg",
		representation(
				.method="character"
		),
		prototype=prototype(
				.description="Hierarchical non parametric Clustering algorithm class",
				.method="ward"
		
		)
) 

#methods
#initialization method 
setMethod("initialize",
		signature="HierNonParamClusterAlg",
		function(.Object,indexObject,method="ward",...){
			.Object <-callNextMethod(.Object,indexObject,...)
			.Object@.method <- method
			
			
			return(.Object)
		})


setMethod("clusterize",
		signature="HierNonParamClusterAlg",
		definition=function(.Object,inputSet,...){
			callNextMethod(.Object,inputSet,...)
	
			bestScore <- -.Machine$double.xmax
			bestClustering <- numeric(0)
			clustSeq <- genClusNumSeq(inputSet)
			#make hierarchical tree
			clObject <- hclust(dist(inputSet$X),method=.Object@.method)
			for(cnum in clustSeq){
				#print("tree cut")
				#cut hierarchical tree at given level in order to make clusters
				clusters <- as.numeric(cutree(clObject,k=cnum))
				#socore obtained clusters
				#print("score clusts")
				score <- ScoreSet(.Object@.indexObject,inputSet,clusters)
				if(is.na(score) || is.infinite(score)){score <- -.Machine$double.xmax}
				if(score > bestScore){
					bestScore <- score
					bestClustering <- clusters
				}
			}
			
			return(bestClustering)
		}
) 
